
#include <core/threadpool.h>

using namespace boost;

typedef function<void (void)> WorkFunc;
typedef std::vector<WorkFunc> Works;

class SimWork
{
 public:
  bool Execute(void)
  {
    (works_.back())();
    works_.pop_back();
    return works_.empty();
  }

  SimWork& Add(const WorkFunc& wf)
  {
    works_.push_back(wf); 
    return *this;
  }

 private:
  Works works_;
};

void Work1halfms(void)
{
  this_thread::sleep_for(chrono::microseconds(500));
  DLOG(INFO) << this_thread::get_id() << ": work 0.5ms";
}

void Work2ms(void)
{
  this_thread::sleep_for(chrono::milliseconds(2));
  DLOG(INFO) << this_thread::get_id() << ": work 2ms";
}

int main(int argc, char** argv)
{
  google::InitGoogleLogging(argv[0]);

  SimWork sw1;
  sw1.Add(Work1halfms).Add(Work1halfms);
  SimWork sw2;
  sw2.Add(Work2ms).Add(Work2ms).Add(Work2ms);

  tp.Add(bind(&SimWork::Execute, &sw1)); 
  tp.Add(bind(&SimWork::Execute, &sw2)); 

  ThreadPool::Instance().Run();
  return 0;
}

